#ifndef __FUNCTION_HANDLEH
#define __FUNCTION_HANDLEH
#include "stdint.h"
#include "stdio.h"
#include <string.h>

typedef void (*fun_p)(void);
typedef uint32_t FUNCID;
#define TASKCNTMAX 20

typedef struct SFUNP_
{
    fun_p funp;
    uint32_t priority;//when the num is biger the priority is higher
    uint32_t isready;
    uint32_t period;
} SFUNP;

typedef struct SFUNH_
{
    SFUNP sfuncp[TASKCNTMAX];
    uint32_t ifunc_period[TASKCNTMAX];//task run period
    uint32_t ifunc_delay[TASKCNTMAX];//when delay is time out run the task
    uint32_t runcnt[TASKCNTMAX];//run cnt in 1 s
    uint32_t runcntmax[TASKCNTMAX];//the max run cnt in 1 s
    uint32_t ifuncp_count;
    uint32_t (*func_reg)(struct SFUNH_ *thiss,fun_p func,uint32_t priority,uint32_t timeout);
    void (*func_handle)(struct SFUNH_ *thiss);
    void (*func_time_handle_1ms)(struct SFUNH_ *thiss);
    void (*func_setready)(struct SFUNH_ *thiss,FUNCID funcid);
    void (*func_setdelay)(struct SFUNH_ *thiss,FUNCID funcid,uint32_t delay);
    void (*func_setperiod)(struct SFUNH_ *thiss,FUNCID funcid,uint32_t period);
    void (*func_waithere)(struct SFUNH_ *thiss,FUNCID funcid,uint32_t timeout);
}SFUNH;

extern SFUNH sfunchandle;

void newsfunh(SFUNH *thiss);
#endif
